package com.ncdnapp.controller;

import com.ncdnapp.core.annotations.WebLog;
import com.ncdnapp.dao.CUserDao;
import com.ncdnapp.dao.UserDao;
import com.ncdnapp.dao.po.UserPO;
import com.ncdnapp.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Param;
import org.noear.solon.core.handle.ModelAndView;
import org.noear.solon.validation.annotation.NotNull;
import org.noear.solon.validation.annotation.Valid;

import java.util.HashMap;
import java.util.Map;

@Controller
@Slf4j
@Valid
public class DemoController {
    @Inject
    private UserService userService;

    @Mapping("/hello")
    @WebLog(response = true)
    public Object hello(@NotNull(message = "name不能为空") String name) {
        Map<String, Object> a = new HashMap<>();
        a.put("name", name);
        log.info("ssssssssssss");
        userService.test();
        //throw new RuntimeException("error");
        return a;
    }

    @Mapping("/hello2")
    public ModelAndView hello2(@Param(defaultValue = "world") String name) {
        return new ModelAndView("hello2.ftl").put("name", name);
    }
}